package com.hmy.finance.manager.order;


import cn.hutool.json.JSONUtil;
import com.hmy.ccp.common.result.FeignResult;
import com.hmy.ccp.error.exception.HMYRuntimeException;
import com.hmy.order.api.bo.request.CustomerInfoApiRequest;
import com.hmy.order.api.bo.response.OrderPrimaryApiResponse;
import com.hmy.order.api.client.OrderServiceClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

@Component
@Slf4j
public class OrderFeignClientRpc {

    @Resource
    private OrderServiceClient orderServiceClient;


    public List<OrderPrimaryApiResponse> getOrderInforsByCustomerInfo(Long customerId, Long signatoryId) {
        FeignResult<List<OrderPrimaryApiResponse>> response = null;
        CustomerInfoApiRequest customerInfoApiRequest = new CustomerInfoApiRequest(customerId, signatoryId);
        log.info("orderServiceClient.getOrderInforsByCustomerInfo params:{}", JSONUtil.toJsonPrettyStr(customerInfoApiRequest));
        response = orderServiceClient.getOrderInforsByCustomerInfo(customerInfoApiRequest);
        log.info("orderServiceClient.getOrderInforsByCustomerInfo response:{}", JSONUtil.toJsonPrettyStr(response));
        if (Objects.isNull(response)) {
            throw new HMYRuntimeException(506300004);
        }
        if (response.isFailed()) {
            throw new HMYRuntimeException(response.getMsgCode(), response.getErrorText());
        }
        return response.getData();
    }


}
